package com.common.displayObjects
{
	import com.common.utils.HashMap;
	import com.common.window.Panel;

	public class PopUpManager extends ComponentChildren
	{
		private var hasmapWindows:HashMap;
		
		public function PopUpManager(_w:Number, _h:Number)
		{
			super(_w, _h);
			
		}
		
		override protected function createChildren():void
		{
			super.createChildren();
			hasmapWindows = new HashMap();
		}
		
		/**
		 * 弹出窗口 
		 * 
		 */		
		public function addPopup(panel:Panel, clearOthers:Boolean = false):void
		{
			if (clearOthers)removeAllPopup();
			if (!hasmapWindows.containsValue(panel))
			{
				hasmapWindows.put(panel, panel);
				panel.x = (width - panel.width) * .5
				panel.y = (height - panel.height) * .5;
				this.addChild(panel);
			}
		}
		
		/**
		 *关闭窗口 
		 * 
		 */		
		public function removePopUp(panel:Panel):void
		{
			if (hasmapWindows.containsValue(panel))
			{
				hasmapWindows.remove(panel);
				this.removeChild(panel);
			}
		}
		
		/**
		 *关闭所有管理下的窗口 
		 * 
		 */		
		public function removeAllPopup():void
		{
			var panel:*;
			for (var i:* in hasmapWindows)
			{
				panel = hasmapWindows[i];
				hasmapWindows.remove(panel);
				this.removeChild(panel);
			}
		}
	}
}